//是否为空
function isEmptyObject(e) {
  var t;
  for (t in e)
    return !1;
  return !0
}

//判断数据是否都存在
function changeProperties(obj, ...ignore) {
  let flag = false;
  for (let name in obj) {
    if (!obj[name]) {
      let condition = ignore.indexOf(name) !== -1;
      if (!condition) {
        flag = true;
        break;
      }
    }
  }
  return flag;
}
//计算天数
function getDayTime(date1, date2) {
  var d1 = new Date(date1.replace(/-/g, "/"));
  var d2 = new Date(date2.replace(/-/g, "/"));
  var days = d2.getTime() - d1.getTime();
  var day = parseInt(days / (1000 * 60 * 60 * 24));  
  return day;
}
//计算日期加减
function handleDate(date, days) {
  var d = new Date(date);
  d.setDate(d.getDate() + days);
  var m = d.getMonth() + 1;
  return d.getFullYear() + '-' + m + '-' + d.getDate();
}
//小数点
function dot(num) {
  if (num.toString().indexOf('.') == -1) {//没有小数点
    return num
  } else {
    //有小数点
    let oArr = num.toString().split('.');
    if (oArr[1].length > 2) {
      return parseFloat(num).toFixed(2);
    } else {
      return num
    }
  }
}
//添加千分符
function comdify(n) {
  var re = /\d{1,3}(?=(\d{3})+$)/g;
  var n1 = n.toString().replace(/^(\d+)((\.\d+)?)$/, function (s, s1, s2) { return s1.replace(re, "$&,") + s2; });
  return n1;
}
//去除千分符
function comdifyback(num) {
  var a = num.toString();
  if (a.indexOf(",")!=-1){
    //包含
    var x = num.split(',');
    return parseFloat(x.join(""));
  }else{
    return num
  }
}
//获取周几
function weekDay(date) {
  var dateIn = new Date(date);
  var day = dateIn.getDay();
  var week;
  day == 1 ? week = "周一" : day == 2 ? week = "周二" : day == 3 ? week = "周三" : day == 4 ? week = "周四" : day == 5 ? week = "周五" : day == 6 ? week = "周六" : week = "周日"
  return week
}
module.exports = {
  comdify: comdify,
  comdifyback: comdifyback,
  dot: dot,
  getDayTime: getDayTime,
  handleDate: handleDate,
  weekDay: weekDay,
  changeProperties: changeProperties,
  isEmptyObject: isEmptyObject
}

